package com.itheima.wms.datasource;


import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.itheima.pinda.base.id.IdGenerate;
import com.itheima.pinda.database.datasource.BaseMybatisConfiguration;
import com.itheima.pinda.database.datasource.MyMetaObjectHandler;
import com.itheima.pinda.database.mybatis.auth.DataScopeInterceptor;
import com.itheima.pinda.database.properties.DatabaseProperties;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 配置一些拦截器
 */
@Configuration
@Slf4j
public class WmsMybatisAutoConfiguration extends BaseMybatisConfiguration {


    public WmsMybatisAutoConfiguration(DatabaseProperties databaseProperties) {
        super(databaseProperties);

    }

    /**
     * 数据权限插件
     *
     * @return DataScopeInterceptor
     */
    @Bean
    @ConditionalOnProperty(name = "pinda.database.isDataScope", havingValue = "true", matchIfMissing = true)
    public DataScopeInterceptor dataScopeInterceptor() {
        return null;
    }


    /**
     * Mybatis Plus 注入器
     *
     * @param idGenerate
     * @return
     */
    @Bean("myMetaObjectHandler")
    @Override
    public MetaObjectHandler getMyMetaObjectHandler(@Qualifier("snowflakeIdGenerate") IdGenerate<Long> idGenerate) {
        return new WmsMetaObjectHandler(idGenerate);
    }
}
